//回复帖子组件
<template>
  <div class="mack-box" v-if="!isHidden" @touchmove.prevent>
    <transition name="fade" @touchmove.prevent>
      <div class="black-mack" @click="down_mask" @touchmove.prevent></div>
    </transition>
    <div class="fill-in">
      <van-cell-group class="van-hairline--surround">
        <van-field
          @blur="out"
          @focus="focusfns"
          v-model="commenInfo.comment_content"
          type="textarea"
          placeholder="说点什么呢..."
          rows="3"
          ref="ref"
        />
      </van-cell-group>
      <div class="fill-reply">
        <van-row type="flex" justify="end" align="center">
          <van-col>
            <p v-if="!commenInfo.comment_content">回复</p>
            <p v-else style="color:#FF894B" @click="replyClick">回复</p>
          </van-col>
        </van-row>
      </div>
    </div>
  </div>
</template>

<script>
import {
  articleComment_save,
  articleComment_saveMsgMedal
} from "@/api/articleComment";
import {
  proposalComment_save,
  proposalComment_saveMsgMedal
} from "@/api/proposalComment";
import other from "@/utils/other";
import { mapGetters } from "vuex";
 import { Debounce, Throttle } from "@/utils";

export default {
  computed: {
    ...mapGetters(["hidden", "commenInfo"])
  },
  data() {
    return {
      isHide: false,
      isShow: false,
      isHidden: false
    };
  },
  methods: {
    focusfns() {
      other.interval();
    },
    out() {
      clearInterval(other.interval());
      other.inputBlur();
    },
    //点击遮罩层
    down_mask() {
      this.$store.dispatch("SetHidden", false);
      this.$emit("isconceal");
    },
    //回复贴子和回复评论
    replyClick: Debounce(function() {
      this.saveObj();
    }, 1000),
    async saveObj() {
      this.commenInfo.time = new Date();
      let query = Object.assign({}, this.commenInfo);
      let res =
        this.$route.query.name == "article"
          ? await articleComment_save(query)
          : await proposalComment_save(query);
      let result = res.data;
      if (result.status == 100) {
        let contenId = result.data;
        this.saveMsgMedal(contenId);
        this.isHidden = true;
        this.$toast.success("评论成功");
        this.$emit("initList");
        this.$store.dispatch("SetHidden", false);
        this.$store.dispatch("SetCommenInfo", {});
        this.$emit("isconceal");
      }
    },
    async saveMsgMedal(contenId) {
      let { data } =
        this.$route.query.name == "article"
          ? await articleComment_saveMsgMedal(contenId)
          : await proposalComment_saveMsgMedal(contenId);
    }
  },
  created() {}
};
</script>

<style lang="scss" scoped>
@import "container";
</style>
